#include<bits/stdc++.h>
using namespace std;
#define M 200007
bool col[M];
int a[M],n,c[M],t;
int n0=0,n1=0;
int main()
{
    int maxn=0;
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int ti=0;ti<t;ti++)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        int x;
        maxn=0;
        for(int j=0;j<114514;j++)
        {
            int ans=0;
            n0=0;
            n1=0;
            for(int i=1;i<=n;i++)
            {
                x=rand()%2;
                if(x==0)
                {
                    if(a[i]==n0) ans+=a[i];
                    n0=a[i];
                }
                else
                {
                    if(a[i]==n1) ans+=a[i];
                    n1=a[i];
                }
            }
            if(ans>maxn) maxn=ans;
        }
        cout<<maxn<<endl;
    }
    return 0;
}
